load("//tools:defs.bzl", "go_library")
load("//tools/go_generics:defs.bzl", "go_template_instance")

package(
    default_applicable_licenses = ["//:license"],
    licenses = ["notice"],
)

go_template_instance(
    name = "context_list",
    out = "context_list.go",
    package = "systrap",
    prefix = "context",
    template = "//pkg/ilist:generic_list",
    types = {
        "Element": "*sharedContext",
        "Linker": "*sharedContext",
    },
)

go_template_instance(
    name = "subprocess_refs",
    out = "subprocess_refs.go",
    package = "systrap",
    prefix = "subprocess",
    template = "//pkg/refs:refs_template",
    types = {
        "T": "subprocess",
    },
)

go_library(
    name = "systrap",
    srcs = [
        "context_list.go",
        "context_queue.go",
        "context_queue_unsafe.go",
        "filters.go",
        "filters_amd64.go",
        "filters_arm64.go",
        "lib_amd64.s",
        "lib_arm64.s",
        "metrics.go",
        "shared_context.go",
        "shared_context_norace.go",
        "shared_context_race.go",
        "stub_amd64.s",
        "stub_arm64.s",
        "stub_defs.go",
        "stub_unsafe.go",
        "subprocess.go",
        "subprocess_amd64.go",
        "subprocess_arm64.go",
        "subprocess_linux.go",
        "subprocess_linux_unsafe.go",
        "subprocess_pool.go",
        "subprocess_refs.go",
        "subprocess_unsafe.go",
        "syscall_thread.go",
        "syscall_thread_amd64.go",
        "syscall_thread_arm64.go",
        "syscall_thread_defs.go",
        "syscall_thread_unsafe.go",
        "sysmsg_thread.go",
        "sysmsg_thread_amd64.go",
        "sysmsg_thread_arm64.go",
        "sysmsg_thread_unsafe.go",
        "systrap.go",
        "systrap_amd64.go",
        "systrap_arm64.go",
        "systrap_arm64_unsafe.go",
        "systrap_profiling.go",
        "systrap_profiling_fake.go",
        "systrap_unsafe.go",
    ],
    visibility = ["//:sandbox"],
    deps = [
        "//pkg/abi/linux",
        "//pkg/atomicbitops",
        "//pkg/bpf",
        "//pkg/context",
        "//pkg/cpuid",
        "//pkg/fd",
        "//pkg/hostarch",
        "//pkg/log",
        "//pkg/memutil",
        "//pkg/metric",
        "//pkg/pool",
        "//pkg/refs",
        "//pkg/safecopy",
        "//pkg/seccomp",
        "//pkg/seccomp/precompiledseccomp",
        "//pkg/sentry/arch",
        "//pkg/sentry/memmap",
        "//pkg/sentry/pgalloc",
        "//pkg/sentry/platform",
        "//pkg/sentry/platform/interrupt",
        "//pkg/sentry/platform/systrap/sysmsg",
        "//pkg/sentry/platform/systrap/usertrap",
        "//pkg/sentry/usage",
        "//pkg/sync",
        "//pkg/syncevent",
        "@org_golang_x_sys//unix:go_default_library",
    ],
)
